package com.buka.communicate.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.buka.communicate.R;
import com.buka.communicate.entity.User;
import com.facebook.drawee.view.SimpleDraweeView;

import net.neiquan.applibrary.base.MyBaseAdapter;
import net.neiquan.applibrary.wight.CommonPopupWindow;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 作者 ： dyj
 * 时间 ： 2016/12/29.
 */

public class FamilyDetailAdapter extends MyBaseAdapter<User, FamilyDetailAdapter.ViewHolder> {

    public FamilyDetailAdapter(Activity context, List data) {
        super(context, data);
    }

    @Override
    public int getItemCount() {
        return 11;
    }

    @Override
    protected ViewHolder getViewHolder() {
        return new ViewHolder(mInflater.inflate(R.layout.item_family_detail, null));
    }

    @Override
    protected void onBindViewHolder_(final ViewHolder holder, int position) {
        holder.mHeadImg.setImageURI("http://img2.imgtn.bdimg.com/it/u=266057472,3867980612&fm=27&gp=0.jpg");
        holder.powerManage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showPowerPopWindow(holder.powerManage);
            }
        });
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.mHeadImg)
        SimpleDraweeView mHeadImg;
        @InjectView(R.id.headLogo)
        ImageView headLogo;
        @InjectView(R.id.userName)
        TextView userName;
        @InjectView(R.id.mRootLL)
        LinearLayout mRootLL;
        @InjectView(R.id.powerManage)
        TextView powerManage;

        ViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }
    }

    private void showPowerPopWindow(TextView powerManage) {
        CommonPopupWindow popupWindow = new CommonPopupWindow.Builder(context)
                //设置PopupWindow布局
                .setView(R.layout.power_manage_pop)
                //设置宽高
                .setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT)
                //设置动画
                .setAnimationStyle(R.style.Animation_Fade)
                //设置背景颜色，取值范围0.0f-1.0f 值越小越暗 1.0f为透明
                .setBackGroundLevel(0.5f)
                //设置PopupWindow里的子View及点击事件
                .setViewOnclickListener(new CommonPopupWindow.ViewInterface() {
                    @Override
                    public void getChildView(final PopupWindow popupWindow, View view, int layoutResId) {
                        TextView cancelTv = (TextView) view.findViewById(R.id.cancelTv);
                        TextView sureTv = (TextView) view.findViewById(R.id.sureTv);
                        cancelTv.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                popupWindow.dismiss();
                            }
                        });
                        sureTv.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                popupWindow.dismiss();
                            }
                        });
                    }
                })
                //设置外部是否可点击 默认是true
                .setOutsideTouchable(true)
                //开始构建
                .create();
        //弹出PopupWindow
        popupWindow.showAtLocation(powerManage, Gravity.CENTER, 0, 0);
    }
}
